package org.dgm.nw.core.filter;

import java.io.IOException;
import java.net.URLEncoder;
import java.util.Enumeration;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

/**
 * 权限过滤类，对每一个请求，都过滤一下
 * 未做处理
 * 
 */
public class QueryHttpFilter implements Filter {
	
	Logger log = Logger.getLogger(this.getClass());

	private String[] excludeURL;

	@Override
	public void doFilter(ServletRequest servletRequest,
			ServletResponse response, FilterChain arg2) throws IOException,
			ServletException {
//		HttpServletRequest localHttpServletRequest = (HttpServletRequest)servletRequest;
//		String utf8 = "UTF-8";
//		String gbk = "GBK";
//		String iso8859 = "ISO8859-1";
//		
//		Enumeration localObject1 = localHttpServletRequest.getHeaderNames();
//	      int i = 0;
//	      String str1="";
//	      Object localObject3;
//	      Object localObject2;
//	      String str6;
//	      while (((Enumeration)localObject1).hasMoreElements()) {
//	        localObject2 = (String)((Enumeration)localObject1).nextElement();
//	        localObject3 = localHttpServletRequest.getHeaders((String)localObject2);
//	        while (((Enumeration)localObject3).hasMoreElements()) {
//	          str6 = (String)((Enumeration)localObject3).nextElement();
//	          str1 += str1 + (String)localObject2 + ":" + str6 + "\n";
//	        }
//	        ++i;
//	      }
//	      String CharacterEncoding = localHttpServletRequest.getCharacterEncoding();
//	      String contenttypeString = localHttpServletRequest.getContentType();
//	      
////	      log.info("head:"+str1); 
//	      log.info("CharacterEncoding:"+CharacterEncoding);
//	      log.info("contenttypeString:"+contenttypeString);
//		  
//	    log.info("未setCharacterEncoding(GBK):userName="+localHttpServletRequest.getParameter("userName"));
//		localHttpServletRequest.setCharacterEncoding("GBK");
//		log.info("已setCharacterEncoding(GBK):userName"+localHttpServletRequest.getParameter("userName"));
//		
//
//		log.info("UTF-8->GBK:"+new String(localHttpServletRequest.getParameter("userName").getBytes(utf8),gbk));
//		log.info("utf8:"+new String(localHttpServletRequest.getParameter("userName").getBytes(utf8)));
//		log.info("ISO8859-1->UTF8:"+new String(localHttpServletRequest.getParameter("userName").getBytes(iso8859),utf8));
//		log.info("ISO8859-1->GBK:"+new String(localHttpServletRequest.getParameter("userName").getBytes(iso8859),gbk));
//		log.info("ISO8859-1:"+new String(localHttpServletRequest.getParameter("userName").getBytes(iso8859)));
//		log.info("GBK->UTF-8:"+new String(localHttpServletRequest.getParameter("userName").getBytes(gbk),utf8));
//		log.info("gbk:"+new String(localHttpServletRequest.getParameter("userName").getBytes(gbk)));
//		log.info(":"+new String(localHttpServletRequest.getParameter("userName").getBytes()));
//		
//		log.info("utf8:"+URLEncoder.encode(localHttpServletRequest.getParameter("userName"), utf8));
//		log.info("gbk"+URLEncoder.encode(localHttpServletRequest.getParameter("userName"), gbk));
//		log.info("iso8859"+URLEncoder.encode(localHttpServletRequest.getParameter("userName"), iso8859));
		
		arg2.doFilter(servletRequest, response);// 这句是关键，没有的话就把servlet过滤了，可以如servlet一样设置跑到自己想要的页面
	}

	@Override
	public void init(FilterConfig filterConfig) throws ServletException {

	}

	@Override
	public void destroy() {
		excludeURL = null;
	}

}
